//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    haveingList: [],
    doneList: [],
    proList: [],
    page: 1,
    pageSize: 6,
    current: 'Haveing',
    apiName: 'getHaveingList',
    loading: false
  },
  onLoad: function () {
    this.getProList();
  },
  navto(e) {
    var uri = e.currentTarget.dataset.uri;
    wx.navigateTo({
      url: uri,
    })
  },
  getProList: function () {
    var _this = this;
    this.setData({
      loading: true
    });
    console.log('loading');
    let url = app.globalData.URL + 'project/' + this.data.apiName;
    setTimeout(function () {
      wx.request({
        url: url,
        data: {
          page: _this.data.page,
          size: _this.data.pageSize
        },
        success(json) {
          _this.setData({
            loading: false
          });
          if (json.data.code == 1) {
            if (_this.data.apiName == 'getHaveingList') {
              _this.setData({
                haveingList: _this.data.haveingList.concat(json.data.data),
                proList: _this.data.haveingList.concat(json.data.data)
              });
            } else {
              _this.setData({
                doneList: _this.data.doneList.concat(json.data.data),
                proList: _this.data.doneList.concat(json.data.data)
              });
            }
            // _this.setData({
            //   proList: json.data.data
            // });

            console.log(_this.data.proList);
            console.log(_this.data.haveingList);
          }
        }
      });
    }, 1000);
    
  },
  handleChange: function (e) {
    this.setData({
      current: e.detail.key,
      apiName: 'get'+e.detail.key+'List'
    });
    if (this.data.doneList.length == 0){
      this.setData({
        proList: []
      });
      this.getProList();
    }else{
      if(this.data.apiName == 'getDoneList'){
        this.setData({
          proList: this.data.doneList
        });
      }else{
        this.setData({
          proList: this.data.haveingList
        });
      }
    }
    
  },
  onReachBottom: function () {
    if(!this.data.loading){
      // this.getProList();
      var _this = this;
      _this.setData({
        page: _this.data.page + 1
      });
      _this.getProList();
    }
  }
})
